/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.siseventos.view.util;

import br.siseventos.model.TbEvento;
import br.siseventos.service.EventoService;
import java.util.ArrayList;
import java.util.List;
import org.primefaces.model.DefaultScheduleEvent;
import org.primefaces.model.ScheduleEvent;

/**
 *
 * @author marcosnatanpacheco
 */
public class ScheduleEventConverter {

    public static List<ScheduleEvent> convertToScheduleEvents(List<TbEvento> eventos) {
        List<ScheduleEvent> lista = new ArrayList<ScheduleEvent>();
        DefaultScheduleEvent evento = null;
        for (TbEvento e : eventos) {
            evento = new DefaultScheduleEvent(e.getNmeEvento(), e.getDtaInicioEvento(), e.getDtaTerminoEvento(), e.getIdtEvento());
            evento.setId(e.getIdtEvento().toString());
            lista.add(evento);
        }
        return lista;
    }

    public static TbEvento convertToEventoPojo(EventoService eventoService, ScheduleEvent e) throws Exception {
        TbEvento evento = null;
        try {
            evento = eventoService.consultar((Integer) e.getData());
        } catch (Exception ex) {
            throw ex;
        }
        return evento;
    }
    
    public static ScheduleEvent convertToScheduleEvent(TbEvento evento){
        ScheduleEvent scheduleEvent = new DefaultScheduleEvent(evento.getNmeEvento(), evento.getDtaInicioEvento(), 
                evento.getDtaTerminoEvento(), evento.getIdtEvento());
        scheduleEvent.setId(evento.getIdtEvento().toString());
        return scheduleEvent;
    }
}
